package com.qitmiaojie.controller;

import cn.hutool.log.Log;
import com.qitmiaojie.controller.utils.Result;
import com.qitmiaojie.pojo.dto.QuestionDto;
import com.qitmiaojie.service.QuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author miaojie
 * @version 1.0
 * @description TODO
 * @date 2023/3/11 11:26
 */
@Slf4j
@RestController
public class QABotController {
    @Autowired
    private QuestionService questionService;

    /***
    * @description 获取问题
    * @param questionDto
    * @return
    * @author
    * @date
    */
    @PostMapping("/api/qabot")
    public Result getAnswer(@RequestBody QuestionDto questionDto) {
        log.info(questionDto.toString());
        return questionService.getAnswer(questionDto.getQuestion());
    }
    @PostMapping("/api/qabot2")
    public Result getAnswer2(@RequestBody QuestionDto questionDto) {
        log.info(questionDto.toString());
        return questionService.getAnswer2(questionDto.getQuestion());
    }
    @PostMapping("/api/qabot2/{id}")
    public Result getAnswer2(@PathVariable String id, @RequestBody QuestionDto questionDto) {
        log.info(questionDto.toString());
        return questionService.startRenwu(id,questionDto.getQuestion());
    }
    /***
    * @description 添加问题
    * @param questionDto
    * @return
    * @author
    * @date
    */
    @PostMapping("/api/qabot/addQuestion")
    public Result addQuestion(@RequestBody QuestionDto questionDto) {
        return questionService.addQuestion(questionDto);
    }
    /***
    * @description 分页查询所有问题
    * @param currentPage
     * @param pageSize
    * @return
    * @author
    * @date
    */
    @GetMapping("/api/qabot/list/{currentPage}/{pageSize}")
    public Result list(@PathVariable("currentPage") Integer currentPage,@PathVariable Integer pageSize){
        return questionService.list(currentPage,pageSize);
    }

    @DeleteMapping("/api/qabot/delQuestion/{id}")
    public Result del(@PathVariable String id){
        return questionService.deleteById(id);
    }
}
